﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

namespace HOBA.AjaxDemo
{
    public partial class NewsReader : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString.Count > 0)
            {
                string news_path = Request.QueryString["f"];
                //string news_path = "news_1_xml";
                news_path = news_path.Trim();
                int dotPos = news_path.LastIndexOf('_');
                news_path = news_path.Remove(dotPos, 1);
                news_path = news_path.Insert(dotPos, ".");

                news_path = Server.MapPath("~/News/" + news_path);
                path.Value = news_path;
                GetNews(news_path);
            }
        }

        private void GetNews(string path)
        {
            if (path.EndsWith(".xml"))
            {
                XmlDocument news = new XmlDocument();
                news.Load(path);
                news_header.InnerHtml = news.GetElementsByTagName("title")[0].InnerText;
                news_description.InnerHtml = news.GetElementsByTagName("description")[0].InnerText;
                news_image.InnerHtml = news.GetElementsByTagName("image")[0].InnerText;
                news_content.InnerHtml = news.GetElementsByTagName("content")[0].InnerText;
                news_info_1.InnerHtml = news.GetElementsByTagName("lastmoddate")[0].InnerText;
                news_info_2.InnerHtml = news.GetElementsByTagName("author")[0].InnerText;
                news_info_3.InnerHtml = news.GetElementsByTagName("source")[0].InnerText;
            }
        }
    }
}
